﻿using System;
using Crowler.Model.CoreComponents.DataAccess;
using Moq;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace Crowler.TestBase
{
    public abstract class DaoTestBaseClass:TestBaseClass,IDisposable
    {
        private static Configuration _configuration;
	    private static ISessionFactory _sessionFactory;
	    protected ISession Session;
        protected Mock<ISessionProvider> SessionProviderMock;


        protected DaoTestBaseClass()
	    {
		    if (_configuration == null)
		    {
		        _configuration = new NHibernateTestConfigurationProvider().CreateNHibernateConfiguration();
		        _sessionFactory = _configuration.BuildSessionFactory();
		    }
            Session = _sessionFactory.OpenSession();
            new SchemaExport(_configuration).Execute(true, true, false, Session.Connection, null);
            SessionProviderMock = new Mock<ISessionProvider>();
            SessionProviderMock.Setup(o => o.Session).Returns(Session);
	    }

        public void Dispose()
	    {
		    Session.Dispose();
	    }
    }
}
